package top.mistgc.mall.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import top.mistgc.mall.common.Result;
import top.mistgc.mall.entity.User;

@RestController
public class TestController {
    @Value("${server.port}")
    private Integer port;

    @Value("${banner1}")
    private String banner1;

    @Value("${banner2}")
    private String banner2;

    @Value("${text}")
    private String text;

    @GetMapping("/test")
    public String test() {
        return "Test";
    }

    @GetMapping("/yml")
    public Integer yml() {
        return port;
    }

    @GetMapping("/testYml")
    public String testYml() {
        return text;
    }

    @GetMapping("/banner")
    public Object banner() {
        List<Object> list = new ArrayList<>();
        HashMap<String, String> hm1 = new HashMap<>();
        hm1.put("img", banner1);
        HashMap<String, String> hm2 = new HashMap<>();
        hm2.put("img", banner2);

        list.add(hm1);
        list.add(hm2);

        return list;
    }

    @GetMapping("/testException")
    public Result testException() {
        List<User> objects = new ArrayList<>();
        Long id = objects.get(0).getId();
        return new Result<>().error();
    }
}
